package com.moter.demo01.requirements;

import com.moter.demo01.requirements.service.OrderService;
import com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo4 {
    public static void main(String[] args) {
        //模拟用户界面
        OrderService orderService = new OrderService();
        List<String> orderIds = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        String id="";
        System.out.println("请输入下单商品编号");
        while(!(id=scanner.next()).equals("0")){
            orderIds.add(id);
        }
        orderService.giveOrder(orderIds);
        System.out.println("下单成功");
        System.out.println("输入1 查询订单");
        String next = scanner.next();
        List<String> list = null;
        if(next.equals("1")){
            System.out.println("您下单了这些商品");
            list= orderService.searchOrder();
            for (int i = 0; i < list.size(); i++) {
                System.out.print(i+": "+list.get(i)+"\t");
            }
        }
        System.out.println("\n输入2：根据序号删除订单,输入-1结束");
        next = scanner.next();
        if(next.equals("2")){
            if(list==null){
                list=orderService.searchOrder();
            }
            List<String> cancerIds = new ArrayList<>();
            int i;
            while((i=scanner.nextInt())!=-1){
                cancerIds.add(list.get(i));
            }
            orderService.cancerOrder(cancerIds);
            System.out.println("取消完成");
        }
    }//a b c d e f g h i j k l m n o p q r s t u v w x y z aa bb cc dd ee ff gg hh ii jj kk
    //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
}
